<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教练员反馈信息页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../res/js/Tools.js"></script>
    <script src="../../res/js/jquery-3.4.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="../../js/login_common.js" charset="utf-8"></script>
    <script src="../../res/layui/layui.js" charset="utf-8"></script>
    <style>
        #btn:hover{
            background: #33aba0;
            cursor: pointer;
        }
        #btn{
            background: #009688;
            color: white;
            width: 100px;
            height: 36px;
            border: 0;
        }
    </style>
    <script>
        $.ajaxSetup({
            async : false
        });
        $(function(){
            $("#btn").click(function () {
                $("#fileone").click();
                $("#fileone").change(function(obj){
                    var fileInput = $('#fileone').get(0).files[0];//获取input控件的file
                    if(fileInput){
                        $("#ts").html(fileInput.name);
                    }
                });

            });
        });
    </script>
</head>
<body>
<form class="layui-form" action="" id="formDId" lay-filter="example" method="post" enctype="multipart/form-data">
    <input type="hidden" id="schemeId" name="schemeId">
    <input type="hidden" name="file1" id="file1">
    <div class="layui-form-item">
        <label class="layui-form-label">实施情况</label>
        <div class="layui-input-block" style="margin-top: 10px">
        <textarea placeholder="请输入您的实施情况" required lay-verify="required"
                  class="layui-textarea" name="resultExp" id="resultExp"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">附件1:*</label>
        <div class="layui-input-block">
            <input type="file" name="fileone" style="display: none" id="fileone"  autocomplete="off"
                   class="layui-input">
            <button id="btn"  type="button" >上传文件</button>
            <a id="ts" target="_blank" style="text-decoration:none"></a>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">实施效果</label>
        <div class="layui-input-block" style="margin-top: 10px">
            <textarea placeholder="请输入您的实施效果" required lay-verify="required"
                      class="layui-textarea" name="resultEffect" id="resultEffect"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="button" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    var form=null;
    layui.use('form', function(){
        form = layui.form;

        //同意提交
        form.on('submit(formDemo)', function(data){
            $("#button").attr("disabled","disabled");
            var formData = new FormData(document.getElementById("formDId"));
            var url="../../../mentalTrainingController/addScheme";
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    if(obj.num==1){
                        layer.msg(obj.msg,{
                            icon:6,
                            time:1000 //1秒关闭(如果不配置默认三秒)
                        },function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            //parent.location.reload();
                        });
                        return false ;
                    }
                },
                error:function(e){
                    layer.msg("错误！！");
                }
            });
            return false;
        });
        var ide = getQueryString("id");
        $("#schemeId").val(ide);
        var resultExp = getQueryString("resultExp");
        if(resultExp!=null){
            fuzhi();
            var str=$("#file1").val();
            if(str.length>1){
                $("#ts").text(str.substring(0,13)+"。。。。。 ."+str.match(/\.([^\.]+)$/)[1]);
                $("#ts").prop("href","../../../"+str);
            }

        }

    });
    function  fuzhi(){
        var id = getQueryString("id");
        var url="../../../mentalTrainingController/findResults";
        var data={schemeId:id};
        $.post(url,data,function(obj){
            $("#file1").val(obj.resultFile);
            $("#resultEffect").val(obj.resultEffect);
            $("#resultExp").val(obj.resultExp);
        },"json");
    }


</script>
</body>
</html>